package fr.cephb.operonj.core.db.binding;

import java.util.HashSet;
import java.util.Set;

import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;


/**
 * BuildBinding
 *
 */
public class SetOfStringsBinding
	extends TupleBinding<Set<String>>
	{
	@Override
	public Set<String> entryToObject(TupleInput input)
		{
		int n= input.readInt();
		Set<String> set= new HashSet<String>(n);
		for(int i=0;i< n;++i)
			{
			set.add(input.readString());
			}
		return set;
		}
	
	@Override
	public void objectToEntry(Set<String> set, TupleOutput output)
		{
		output.writeInt(set.size());
		for(String s:set)
			{
			output.writeString(s);
			}
		}
	}
